﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.DAO;

namespace SCRUM.Core.BusinessObjects
{
    /// <summary>
    /// Thread groups comments added by user to some entity
    /// </summary>
    public class Thread
    {
        /// <summary>
        /// ID of thread
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// Threads name 
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Type of entity thread belongs to
        /// </summary>
        public string TypeOfEntity { get; set; }

        /// <summary>
        /// ID of entity thread belongs to
        /// </summary>
        public int EntityID { get; set; }

        /// <summary>
        /// List of comments that are in thread
        /// </summary>
        public List<Comment> Comments
        {
            get
            {
                // Lazy loading
                if (this.Comments == null)
                {
                    this.Comments = DAOComment.GetAllCommentsForThread(ID);
                }
                return this.Comments;
            }
            set
            {
                this.Comments = value;
            }
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        public Thread()
        { 
        }

        /// <summary>
        /// Constructor with required parameters
        /// </summary>
        /// <param name="ID">ID of thread</param>
        /// <param name="name">Name of thread</param>
        /// <param name="type">Type of entity thread belongs to</param>
        /// <param name="entityID">ID of entity thread belongs to</param>
        public Thread(int ID, string name, string type, int entityID)
        {
            this.ID = ID;
            this.Name = name;
            this.TypeOfEntity = type;
            this.EntityID = entityID;
        }

        /// <summary>
        /// String representation of thread
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }
    }
}
